package com.yihusitian.zsxq.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yihusitian.zsxq.pojo.dto.Image;
import com.yihusitian.zsxq.service.IDGenerator;
import org.springframework.stereotype.Service;
import com.yihusitian.zsxq.mapper.ImageMapper;
import com.yihusitian.zsxq.pojo.data.ImageDO;
import com.yihusitian.zsxq.service.ImageService;

import java.util.List;

/**
 * @Description TODO
 * @Author LeeHo
 * @Date 2021-03-25 17:00:13
 */
@Service
public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageDO> implements ImageService {

    @Override
    public void createImages(List<Image> images, Long commentId) {
        if (CollectionUtil.isEmpty(images)) {
            return;
        }
        images.forEach(image -> {
            ImageDO.builder()
                    .id(image.getImage_id())
                    .commentId(commentId)
                    .type(image.getType())
                    .large(image.getLarge() == null ? StrUtil.EMPTY : JSONUtil.toJsonStr(image.getLarge()))
                    .original(image.getOriginal() == null ? StrUtil.EMPTY : JSONUtil.toJsonStr(image.getOriginal()))
                    .thumbnail(image.getThumbnail() == null ? StrUtil.EMPTY : JSONUtil.toJsonStr(image.getThumbnail()))
                    .build()
                    .insert()
            ;
        });
    }
}